package com.xkk.controller;

import com.xkk.pojo.Register;
import com.xkk.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class registerController {
    @Autowired
   RegisterService registerService;

    //添加员工
    @RequestMapping("/register")
    public String toAddAdd(Model model) {
        Register register = new Register();
        model.addAttribute("table",register);
        return "table";
    }

    @PostMapping("/addadd")
    public String toEmpEmp(Register register) {
        registerService.addregister(register);
        return "redirect:/show";
    }

/*显示*/
    @RequestMapping("/show")
    public String list(Model model) {
        List<Register> list = registerService.selectAllregister();
        model.addAttribute("list", list);
        return "emp/register";
    }

    //删除员工信息
    @GetMapping("/dele/{id}")
    public String deleteEmp(@PathVariable("id") int id) {
        registerService.deleteregister(id);
        return "redirect:/show";
    }
    /*返回主页面*/
    @RequestMapping("/login")
    public String login() {
        return "index";
    }
}
